package xyz.hujf.tool.autoclass;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @author Hujf
 * @title: Atomic
 * @date 2021-04-27 14:57
 * @description: TODO
 */
public class Atomic {
    private static AtomicLong atomicLong = new AtomicLong();

    private static Integer[] arrayOne = new Integer[] {0 , 1 , 2 , 3 , 0 , 5 , 6, 0 , 56 , 0} ;
    private static Integer[] arrayTwo =new Integer[] {10 , 1 , 2, 3 , 0 , 5 , 6 , 0 , 56 , 0} ;

    public static void main(String[] args) throws InterruptedException {
        Thread t1 = new Thread(()-> {
          int size = arrayOne.length;

          for(int i=0;i<size;i++){
              if(arrayOne[i].intValue()==0){
                  atomicLong.incrementAndGet();
              }
          }
        });

        Thread t2 = new Thread(()-> {
            int size = arrayOne.length;

            for(int i=0;i<size;i++){
                if(arrayTwo[i].intValue()==0){
                    atomicLong.incrementAndGet();
                }
            }
        });
        t1.start();
        t2.start();

        t1.join();
        t2.join();

        System.out.println("atomicLong.get() = " + atomicLong.get());
    }
}
